<template>
  <div class="container  order-list">
    <!-- 面包屑导航 -->
    <breadcrumb :breadcrumbConfig=breadcrumbConfig></breadcrumb>
    <!--    <breadcrumb></breadcrumb>-->
    <!-- 面包屑导航 -->

    <div class="content">
      <h2 class="padding">客服订单</h2>
      <!--      <h3>数据筛选</h3>-->
      <div>
        <el-form :inline="true" id="searchForm" :model="searchForm" ref="searchForm" class="search-form">
          <el-form-item label="订单编号" prop="orderNo">
            <el-input
                v-model.trim="searchForm.orderNo"
                size="small"
                placeholder="请输入订单编号"
                oninput="value=value.replace(/[^0-9.]/g,'')"
                filterable
                clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="关联订单号" prop="platformOrderNo">
            <el-input
                v-model.trim="searchForm.platformOrderNo"
                size="small"
                oninput="value=value.replace(/[\W]/g,'')"
                placeholder="请输入关联订单号"
                clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="客户信息" prop="postUserInfo">
            <el-input
                v-model="searchForm.postUserInfo"
                size="small"
                placeholder="请输入客户信息"
                clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="公司部门" prop="orgCode">
            <el-cascader
                :options="orgCodeList"
                v-model="searchForm.orgCode"
                placeholder="请选择公司部门"
                size="small"
                :show-all-levels=false
                :props="{ label: 'orgName', value: 'orgCode', checkStrictly: true }"
                filterable
                clearable
                @change="onChangeCategory"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="跟进客服" prop="applierId">
            <el-select
                v-model="searchForm.applierId"
                placeholder="请选择跟进客服"
                size="small"
                filterable
                clearable
            >
              <el-option
                  v-for="item in salesAuthority"
                  :key="item.id"
                  :label="item.reallyName"
                  :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <!--
          <el-form-item label="店铺" prop="shopId">
            <el-select
                v-model="searchForm.shopId"
                placeholder="请选择状态"
                size="small"
                filterable
                clearable
            >
              <el-option
                  v-for="item in shopDataList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="订单类型" prop="orderType">
              <el-select
                  v-model="searchForm.orderType"
                  placeholder="请选择订单类型"
                  size="small"
                  filterable
                  clearable
              >
                <el-option
                    v-for="item in dictionaries.order_main_type"
                    :key="item.dictId"
                    :label="item.dictName"
                    :value="item.dictId"
                >
                </el-option>
              </el-select>
            </el-form-item>
          <el-form-item label="来源平台" prop="platformId">
            <el-select
                v-model="searchForm.platformId"
                placeholder="请选择平台"
                size="small"
                filterable
                clearable
            >
              <el-option
                  v-for="item in platformDataList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="提交审核时间" prop="createdTime">
            <el-date-picker
                v-model="searchForm.createdTime"
                type="daterange"
                size="small"
                @change="onChangeTime"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" plain size="small"
            @click="fetchData('search')"
            @keyup.enter="fetchData('search')"
            >查询</el-button>
            <el-button
                type="primary"
                size="small"
                plain
                @click="fetchData('reset')"
            >重置
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="content">
      <h3>数据列表</h3>

      <div class="btn-list tabclass">
        <div class="">
          <el-button
              class="tabBtn"
              plain
              :disabled="loading"
              :type="
              currentTab == currentTabStatus.all ? 'primary' : 'info'
            "
              @click="onChangeCurrentTab(currentTabStatus.all)"
          >全部
          </el-button
          >
          <el-button
              class="tabBtn"
              plain
              :disabled="loading"
              :type="
              currentTab == currentTabStatus.beforeSubmit
                ? 'primary'
                : 'info'
            "
              @click="onChangeCurrentTab(currentTabStatus.beforeSubmit)"
          >待提交({{ statusCount.waitingSubmitCount }})
          </el-button
          >
          <el-button
              class="tabBtn"
              plain
              :disabled="loading"
              :type="
              currentTab == currentTabStatus.underReview
                ? 'primary'
                : 'info'
            "
              @click="onChangeCurrentTab(currentTabStatus.underReview)"
          >审核订单({{ statusCount.processCount }})
          </el-button
          >
          <el-button
              class="tabBtn"
              plain
              :disabled="loading"
              :type="
              currentTab == currentTabStatus.shipments ? 'primary' : 'info'
            "
              @click="onChangeCurrentTab(currentTabStatus.shipments)"
          >发货前({{ statusCount.prePostCount }})
          </el-button
          >
          <el-button
              class="tabBtn"
              plain
              :disabled="loading"
              :type="
              currentTab == currentTabStatus.signFor ? 'primary' : 'info'
            "
              @click="onChangeCurrentTab(currentTabStatus.signFor)"
          >待签收({{ statusCount.preReceivedCount }})
          </el-button
          >
          <el-button class="tabBtn"
                     plain
                     :disabled="loading"
                     :type="
              currentTab == currentTabStatus.accomplish ? 'primary' : 'info'
            "
                     @click="onChangeCurrentTab(currentTabStatus.accomplish)"
          >已完成
          </el-button
          >
          <el-button class="tabBtn"
                     plain
                     :disabled="loading"
                     :type="
              currentTab == currentTabStatus.close ? 'primary' : 'info'
            "
                     @click="onChangeCurrentTab(currentTabStatus.close)"
          >已关闭
          </el-button
          >
        </div>
        <div>
          <el-button v-if="parArray.indexOf('applier_outWeb_export') != -1" class="yellowBtn" type="warning"
                     @click="showDialog('站外订单物流透视', '400px', 'transparent')">站外订单物流透视
          </el-button>
          <el-button v-if="parArray.indexOf('order_daochu') != -1" class="blueBtn" type="primary"
                     @click="onApplierExport">导出
          </el-button>
          <el-button v-if="parArray.indexOf('tianlanExportCode') != -1" class="blueBtn serviceDerive" type="primary" :loading="loadingState"
                     @click="serviceDerive">健驰订单数据导出
          </el-button>
          <el-button v-if="parArray.indexOf('kefuExportCode') != -1" class="blueBtn promotionDerive" type="primary" :loading="loadingStateTwo"
                     @click="promotionDerive">业务订单数据导出
          </el-button>
          <el-button v-if="parArray.indexOf('serviceDeriveStatistics') != -1" class="blueBtn serviceDeriveTwo" :loading="loadingStateThree"
                     type="primary" @click="serviceDeriveStatistics">健驰统计数据导出
          </el-button>
          <el-button v-if="parArray.indexOf('promotionDeriveStatistics') != -1" class="blueBtn promotionDeriveTwo" :loading="loadingStateFour"
                     type="primary" @click="promotionDeriveStatistics">业务统计数据导出
          </el-button>
        </div>

      </div>
      <orders-list-table v-loading="loading" :dataList="page.list" :heightStr='columns.height' :typeStr='columns.type' :config="columns.config"
                         :sortObj="columns.sortObj"
                         @onTableShowDialogCom="resTableShowDialog"
                         @outTableCancelOrderMsg="onCancelOrderMsg"
                         @tableSelectionChange="handleSelectionChange"></orders-list-table>
      <!-- 分页start -->
      <div class="page">
        <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.pageNo"
            :page-sizes="[3, 5, 10, 20, 50]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.totalNum"
        >
        </el-pagination>
      </div>
      <!-- 分页end -->
    </div>
    <!--========================== el-dialog =================================-->
    <el-dialog
        :title="dialog.title"
        :visible.sync="dialog.visible"
        :width="dialog.width"
        :append-to-body="true"
    >
      <template v-if="dialog.type === 'modifyOrderNoOne'">
        <modify-order-no :orderObj="dialog.row" :type="dialog.type" ref="modifyOrderNo" source="service"
                         @submitState="modifyState"></modify-order-no>
      </template>
      <template v-if="dialog.type === 'logisticsMessageOne'">
        <step-progress :orderObj="dialog.row" type="logisticsMessageOne"></step-progress>
      </template>
      <template v-if="dialog.type === 'shenheStep'">
        <step-progress :orderObj="dialog.row" :processFunc="dictionaries.process_func"
                       type="shenheStep"></step-progress>
      </template>
      <template v-if="dialog.type === 'transparent'">
        <div>
          <upload-file ref="transparent" @dialogVisible="closeDialog"></upload-file>
        </div>
      </template>
      <template v-if="dialog.type === 'closeOrder'">
        <el-radio-group v-model="setCloseOrder">
          <el-radio v-for="(item,index) in dictionaries.order_main_close_reason" :key="index" class="setPay_payment"
                    :label="item.dictId">{{ item.dictName }}
          </el-radio>
        </el-radio-group>
        <div class="dialogBtnright dialogBtnright_right" style="margin-top:20px">
          <el-button class="setPay_payment_btn_quxiao" @click="dialog.visible=false">取 消</el-button>
          <el-button class="setPay_payment_btn_queren" type="primary" @click="handlerCloseOrderSubmit">确 定</el-button>
        </div>
      </template>
      <div v-if="dialog.type === 'modifyOrderNoOne' || dialog.type === 'transparent'" class="dialog-btn">
        <el-button class="setPay_payment_btn_quxiao" type="primary" plain
                   @click="closeDialog(); $refs.transparent.$refs.uploadFileXls.clearFiles();">取消
        </el-button>
        <el-button class="setPay_payment_btn_queren" type="primary"
                   @click="actionDialog(); $refs.transparent.$refs.uploadFileXls.clearFiles();">确认
        </el-button>
      </div>

    </el-dialog>
    <!--=========================== el-dialog end================================-->
  </div>
</template>

<script>
import formFiled from '@/components/form/index'
import breadcrumb from '@/components/breadcrumb'
import mixinsCommon from './mixins/common.js'
import mixinsOrderList from './mixins/mixinsOrderList.js'

import modifyOrderNo from './components/modifyOrderNo'
import StepProgress from '@/components/StepProgress'
import StepLogistics from './components/StepLogistics'

import UploadFile from '@/components/upload/UploadFile.vue'

// import { mapMutations } from 'vuex'
// import { mapGetters } from 'vuex'
import OrdersListTable from './components/OrdersListTable'

export default {
  mixins: [mixinsCommon, mixinsOrderList],
  components: {
    formFiled,
    breadcrumb,
    OrdersListTable,
    StepProgress,
    StepLogistics,
    modifyOrderNo,
    UploadFile
  },
  data () {
    return {
      loadingState: false,
      loadingStateTwo: false,
      loadingStateThree: false,
      loadingStateFour: false,
      loading: false,
      parArray: [],
      userType: '',
      columns: {
        type: 'all',
        height: '5000px',
        sortObj: {},
        config: []
      },
      // 公共  column
      columnCommon: {
        type: 'common',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [
          { type: 'selection', width: 50 },
          { prop: 'payTypeLabel', label: '商品名称', width: 200, slot: 'goods' },
          { prop: 'quantity', label: '数量', width: 60 },
          { prop: 'postName', label: '收件人', width: 120, slot: 'contact' },
          { prop: 'postDetailedAddress', label: '收货地址', width: 140 },
          { prop: 'receivedAmount', label: '支付金额', width: 100, slot: 'amount' },
          { prop: 'statusLabel', label: '订单状态', width: 80, slot: 'order' },
          { prop: 'subsetSatusLabel', label: '审核状态', width: 80, slot: 'examine' },
          { prop: 'remarks', label: '备注/留言', width: 150, slot: 'remarks' }
        ]
      },
      // 全部
      columnAll: {
        type: 'all',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: []
      },
      // 待提交
      columnSubmitted: {
        type: 'submitted',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: []
      },
      // 审核订单
      columnExamine: {
        type: 'examine',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [{ prop: 'approveReason', label: '不通过原因', width: 150 }]
      },
      // 发货前
      columnBeforeShipment: {
        type: 'beforeShipment',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: []
      },
      // 待签收
      columnWaitSignFor: {
        type: 'waitSignFor',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: []
      },
      // 已完成
      columnFinish: {
        type: 'finish',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: []
      },
      // 已关闭
      columnClose: {
        type: 'close',
        sortObj: { prop: 'marketPrice', order: 'descending' }, // 排序
        config: [
          { prop: 'operation', label: '操作记录', width: 150, slot: 'operation' }
        ]
      },
      multipleSelection: '', // 多选
      cancelOrderId: '', // 取消订单id
      setCloseOrder: '', // 取消订单参数
      statusCount: {
        waitingSubmitCount: 0, // 提交订单前 待提交
        closedCount: 0, // 已关闭数量
        finishedCount: 0, // 已完成数量
        prePostCount: 0, // 待发货数量
        preReceivedCount: 0, // 待签收数量
        processCount: 0, // 审核中数量
        totalCount: 0 // 全部数量
      },
      searchForm: {
        orderNo: '', // 	订单编号 	body 	false 	string
        platformOrderNo: '', // 	关联订单号 	body 	false 	string
        postUserInfo: '', // 	收货人信息 	body 	false 	string
        orgCode: [], // 公司部门
        payType: '', // 	支付方式（字典：order_pay_type）1.在线支付（支付宝、微信）2.代收3.货到付款 	body 	false 	string
        subsetStatus: '', // 	订单子状态（字典：order_main_subset_status） 	body 	false 	string
        applierId: '', // 	跟进客服id（数据来源：/neworder/order/submitTask/applierList） 	body 	false 	integer(int64)
        orderType: '', // 订单类型
        platformId: '', // 	平台id（数据来源：/order/v1-2/platform/dataList） 	body 	false 	integer(int64)
        shopId: '', // 	店铺id（数据来源：/order/v1-2/shop/dataList） 	body 	false 	integer(int64)
        createdTime: '', // 	提交时间
        orderTimeStart: '', // 	提交时间-开始（格式：2022-03-11） 	body 	false 	string
        orderTimeEnd: '' // 	提交时间-结束（格式：2022-03-21） 	body 	false 	string
      },
      currentTab: 8, // 当前列表状态
      // 分配状态
      currentTabStatus: {
        all: 8, // 全部
        beforeSubmit: 99, // 提交订单前 待提交
        underReview: 1, // 审核中
        shipments: 2, // 发货前
        signFor: 3, // 代签收
        accomplish: 4, // 已完成
        close: 5 // 已关闭
      },
      columnTitle: this.column,
      breadcrumbConfig: {
        list: [
          {
            title: '订单管理',
            type: '#ff0000',
            path: ''
          },
          {
            title: '客服订单',
            type: '1',
            path: ''
          }

        ]
      },
      page: { list: [], pageNo: 1, pageSize: 10, totalNum: 0, currentPage: 1, status: '' },
      rQuery: {}
    }
  },
  watch: {
    $route: {
      handler (val, oldVal) {
        // console.log(val, this.$route.query.state);
        if (val.query.state) {
          this.onChangeCurrentTab(Number(this.$route.query.state))
          this.currentTab = Number(val.query.state)
        }
      },
      // 深度观察监听
      deep: true
    }
  },
  created () {
    const rQuery = this.$route.query
    this.rQuery = rQuery
    document.onkeyup = e => {
      console.log(e, 'e')
      if (e.keyCode === 13) {
        this.fetchData('search')
      }
    }
    this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    if (this.userInfo.id != 1) {
      this.searchForm.applierId = this.userInfo.id
    }

    // 权限设定判断
    this.limits = JSON.parse(sessionStorage.getItem('limit'))
    const params = this.limits.buttonTreeDto.filter(
      (item) => item.menuCode === 'orderListCode'
    )
    params[0].buttonList.forEach((item) => {
      this.parArray.push(item.code)
    })
    // this.columns = this.columnCommon
    // console.log(typeof this.$route.query.state, this.$route.query.state)

    // this.fetchData()
    this.initSearchList()// 初始化，搜索需要的列表数据
    this.userType = JSON.parse(sessionStorage.getItem('userInfo')).userType
    setTimeout(_ => {
      // console.log(this.dictionaries.export_model_url)
    }, 500)
  },
  mounted () {
    this.$nextTick(_ => {
      const rQuery = this.rQuery
      if (rQuery.state) {
        this.onChangeCurrentTab(Number(rQuery.state))
        this.currentTab = rQuery.state
      } else {
        this.onChangeCurrentTab() // fetchData 在这里执行
      }
    })
  },
  methods: {
    // 复制客服名字
    copyServiceName (row) {
      const that = this
      // let inline = this.line.find((res) => res.id == row.userDitch);
      const info =
          (row.applierName == null ? '无' : row.applierName)
      that.$copyText(info).then(
        function (e) {
          that.$message({
            type: 'success',
            message: '复制成功'
          })
        },
        function (e) {
          that.$message({
            type: 'warning',
            message: '复制失败'
          })
        }
      )
    },

    onChangeCategory (e) {
      console.log(e)
    },

    tableShow (row, index) {
      if (row.approveStatusLabel) {
        this.getTaskHistory(row.orderNo, index)
      }
      // console.log(row, index)
    },
    // 查看审批流程
    getTaskHistory (orderId, index) {
      const data = {
        funcCode: '1',
        busId: orderId
      }
      if (this.page.list[index].history.length !== 0) {
        // console.log(this.page.list[index].history)
      } else {
        this.$api.getTaskHistory(data).then(res => {
          if (res.code === 0) {
            // this.page.list[index].statusLabel = res.data.records
            this.orderShenHeState = res.records
            this.page.list[index].history = res.data.records
          }
        })
      }
    },

    // 关闭订单打开弹框
    cancelOrder (row) {
      this.setCloseOrder = ''
      this.dialog.visible = true
      this.dialog.title = '取消订单'
      this.dialog.width = '540px'
      this.dialog.type = 'closeOrder'
      this.cancelOrderId = row.orderId
    },

    /*
    testFun () {
      console.log(this.platformList)
      this.$store.dispatch('common/getPlatformList')
      // this.SET_PLATFORM_LIST()
    },
    */
    // 修改售后物流单号，提交状态
    modifyState (state) {
      // console.log('修改售后物流单号，提交状态', state)
      // 提交后，关闭并还原值
      this.closeDialog()
      this.fetchData()
    },
    /**
     * @param type
     * @param isGoOne 是否返回第一页
     */
    fetchData (type, isGoOne) {
      this.loading = true
      // debugger
      if (type === 'reset') {
        this.$refs['searchForm'].resetFields()
        this.page.pageNo = 1
        this.page.pageSize = 10
        this.page.currentPage = 1
        // 时间重置
        this.searchForm.orderTimeStart = ''
        this.searchForm.orderTimeEnd = ''
      }
      let params = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
        status: this.currentTab == 8 ? '' : this.currentTab
      }
      const searchForm = this.searchForm
      params = Object.assign(params, searchForm)
      params.orgCode = typeof (this.searchForm.orgCode) === 'string' ? this.searchForm.orgCode : this.searchForm.orgCode[this.searchForm.orgCode.length - 1]

      // console.log(this.searchForm, 'searchForm')
      if (type === 'search') {
        // 如果页码大于 1 列表数据大于 1， 停留在当前页
        if (isGoOne && this.page.pageNo > 1 && this.page.list.length > 1) {
          params.pageNo = this.page.pageNo
        } else { // 正常 跳转到 第一页
          this.page.currentPage = 1
          this.page.pageNo = 1
        }
        const searchForm = this.searchForm
        params.pageNo = this.page.pageNo
        params = Object.assign(params, searchForm)
        params.orgCode = typeof (this.searchForm.orgCode) === 'string' ? this.searchForm.orgCode : this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
        // params.pageNo = 1
        // if (this.currentTab === this.currentTabStatus.underReview) { params.approveStatus = 1 }
        // 去除字符串 前后 空格
        for (const item in params) {
          if (typeof params[item] === 'string') {
            params[item] = params[item].trim()
          }
        }
      }
      // 审核中 添加 参数 approveStatus
      // if (this.currentTab === this.currentTabStatus.underReview) { params.approveStatus = 1 }
      // 全部 或 审核中 清除 参数 status
      // if (this.currentTab === 8) { delete params.status }
      this.$api.servicePageList(params).then((res) => {
        if (res.code === 0) {
          // 每个数据上添加一个 history 数组
          res.data.list.forEach(item => {
            item['history'] = []
            item.goodsNameCn = []
            item.approveReason = item.approveReason ? item.approveReason : '-'
            // item.goodsNameCn = item.goodsName.split(',')
          })
          this.page.list = res.data.list
          this.page.totalNum = res.data.totalNum
          // if(this.currentTab === 1){params.status = 1}
          this.getStatusCount(params)// 订单数量统计查询
          this.loading = false
        } else {
          console.log('goodsPageList - 失败', type)
        }
      }).catch((err) => {
        console.log(err)
        this.loading = false
      })
    },
    handleCurrentChange (currentChange) {
      this.page.pageNo = currentChange
      this.fetchData()
      console.log(currentChange, 'currentChange')
    },
    handleSizeChange (sizeChange) {
      this.page.pageNo = 1
      this.page.currentPage = 1
      this.page.pageSize = sizeChange
      this.fetchData()
    },

    // 订单数量统计查询
    getStatusCount (params) {
      // const params = {}
      this.$api.getStatusCount(params).then((res) => {
        this.statusCount = res.data
      }).catch((err) => {
        console.log(err)
      })
    },
    onChangeCurrentTab (status) {
      let tempStatus
      // status ? this.currentTab = status : this.currentTab
      if (status) {
        this.currentTab = status
        tempStatus = status
      } else {
        tempStatus = this.currentTab
      }
      let configTemp = []
      let configStatusTemp = []
      let strTemp = ''
      // const columnCommon = Object.assign({}, this.columnCommon)
      // console.log(columnCommonConfig)
      // this.columns = []
      switch (tempStatus) {
        case 99:
          // console.log('提交订单前 待提交')
          strTemp = 'submitted'
          configTemp = [...this.columnCommon.config]
          configTemp.splice(7, 1) // 删除审核状态
          configTemp.splice(6, 1) // 删除订单状态
          break
        case 1:
          // console.log('审核中')
          strTemp = 'examine'
          configStatusTemp = [...this.columnExamine.config]
          configTemp = [...this.columnCommon.config]
          configTemp.splice(3, 2) // 删除 收货人 删除 地址
          configTemp.splice(9, 0, configStatusTemp[0]) // 添加 不通过原因
          break
        case 2:
          // console.log('发货前')
          configTemp = [...this.columnCommon.config]
          strTemp = 'beforeShipment'
          configTemp.splice(7, 1) // 删除 审核状态
          break
        case 3:
          // console.log('待签收')
          strTemp = 'waitSignFor'
          configTemp = [...this.columnCommon.config]
          configTemp.splice(7, 1) // 删除 审核状态
          break
        case 4:
          // console.log('已完成')
          strTemp = 'finish'
          configTemp = [...this.columnCommon.config]
          configTemp.splice(7, 1) // 删除 审核状态
          break
        case 5:
          // console.log('已关闭')
          strTemp = 'close'
          configStatusTemp = [...this.columnClose.config]
          configTemp = [...this.columnCommon.config]
          configTemp.splice(10, 0, configStatusTemp[0]) // 添加 操作记录
          break
        default:
          // console.log('全部')
          strTemp = 'all'
          configTemp = [...this.columnCommon.config]
          // configTemp.splice(8, 1) // 删除 下单时间
      }
      this.columns.type = strTemp
      this.columns.config = Array.from(new Set(configTemp))
      console.log(this.columns)
      this.page.pageNo = 1
      this.page.pageSize = 10
      this.page.currentPage = 1
      this.$nextTick(_ => {
        // this.fetchData('reset')
        const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
        // id 为 1 的超级管理员不做默认
        if (this.isFirst > 2 || userInfo.id === 1) {
          this.fetchData('search')
        }
        this.isFirst++
      })
    },
    // 初始化，搜索需要的列表数据
    initSearchList () {
      const params = { pageNo: 1, pageSize: 1001 }
      this.getOrgTreeList(params) // 公司部门
      this.getSalesAuthority(params) // 跟进客服
      this.getPlatformDataList(params) // 平台
      this.getShopDataList(params) // 店铺
    },
    // 复制物流单号
    copyLogistics (row) {
      const that = this
      const info =
          (row.logisticsNumber == null ? '无' : row.logisticsNumber)
      that.$copyText(info).then(
        function (e) {
          that.$message({
            type: 'success',
            message: '复制成功'
          })
        },
        function (e) {
          that.$message({
            type: 'warning',
            message: '复制失败'
          })
        }
      )
    },
    onChangeTime (time) {
      if (time) {
        this.searchForm.orderTimeStart = time[0]
        this.searchForm.orderTimeEnd = time[1]
      } else {
        this.searchForm.orderTimeStart = ''
        this.searchForm.orderTimeEnd = ''
      }
    },

    // 健驰订单数据导出
    serviceDerive () {
      this.loadingState = true
      if (this.searchForm.orderTimeStart == '' || this.searchForm.orgCode.length == 0) {
        this.$message.warning('请选择时间和公司部门！')
        this.loadingState = false
        return
      }
      const data = Object.assign({}, this.searchForm)
      data.startTime = this.searchForm.orderTimeStart
      data.endTime = this.searchForm.orderTimeEnd
      let orgCode
      // console.log(typeof this.searchForm.orgCode)
      if (typeof this.searchForm.orgCode === 'string') {
        orgCode = this.searchForm.orgCode
      } else {
        orgCode = this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
      }
      /*
      const data = {
        startTime: this.searchForm.orderTimeStart,
        endTime: this.searchForm.orderTimeEnd,
        // path: this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
        path: orgCode
      }
      */
      data.path = orgCode
      data.orgCode = orgCode
      // console.log(params, 'this.currentTab')
      this.$api.tianlanExport(data).then((res) => {
        console.log(res, 'res')
        this.downloadlink(res.data)
        this.loadingState = false
      }).catch((err) => {
        console.log(err)
      })
    },
    // 健驰统计数据导出
    serviceDeriveStatistics () {
      this.loadingStateThree = true
      if (this.searchForm.orderTimeStart == '' || this.searchForm.orgCode.length == 0) {
        this.$message.warning('请选择时间和公司部门！')
        this.loadingStateThree = false
        return
      }
      const data = Object.assign({}, this.searchForm)
      data.startTime = this.searchForm.orderTimeStart
      data.endTime = this.searchForm.orderTimeEnd
      let orgCode
      if (typeof this.searchForm.orgCode === 'string') {
        orgCode = this.searchForm.orgCode
      } else {
        orgCode = this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
      }
      /*
      const data = {
        startTime: this.searchForm.orderTimeStart,
        endTime: this.searchForm.orderTimeEnd,
        // path: this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
        path: orgCode
      }
      */
      data.path = orgCode
      data.orgCode = orgCode
      this.$api.serviceDeriveStatistics(data).then((res) => {
        console.log(res, 'res')
        this.downloadlink(res.data)
        this.loadingStateThree = false
      }).catch((err) => {
        console.log(err)
      })
    },
    // 天兰统计数据导出
    promotionDeriveStatistics () {
      this.loadingStateFour = true
      if (this.searchForm.orderTimeStart == '' || this.searchForm.orgCode.length == 0) {
        this.$message.warning('请选择时间和公司部门！')
        this.loadingStateFour = false
        return
      }
      const data = Object.assign({}, this.searchForm)
      data.startTime = this.searchForm.orderTimeStart
      data.endTime = this.searchForm.orderTimeEnd
      let orgCode
      if (typeof this.searchForm.orgCode === 'string') {
        orgCode = this.searchForm.orgCode
      } else {
        orgCode = this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
      }
      /*
      const data = {
        startTime: this.searchForm.orderTimeStart,
        endTime: this.searchForm.orderTimeEnd,
        // path: this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
        path: orgCode
      }
      */
      data.path = orgCode
      data.orgCode = orgCode
      this.$api.promotionDeriveStatistics(data).then((res) => {
        console.log(res, 'res')
        this.downloadlink(res.data)
        this.loadingStateFour = false
      }).catch((err) => {
        console.log(err)
      })
    },
    // 天兰订单数据导出
    promotionDerive () {
      this.loadingStateTwo = true
      if (this.searchForm.orderTimeStart == '' || this.searchForm.orgCode.length == 0) {
        this.$message.warning('请选择时间和公司部门！')
        this.loadingStateTwo = false
        return
      }
      const data = Object.assign({}, this.searchForm)
      data.startTime = this.searchForm.orderTimeStart
      data.endTime = this.searchForm.orderTimeEnd
      let orgCode
      if (typeof this.searchForm.orgCode === 'string') {
        orgCode = this.searchForm.orgCode
      } else {
        orgCode = this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
      }
      /*
      const data = {
        startTime: this.searchForm.orderTimeStart,
        endTime: this.searchForm.orderTimeEnd,
        // path: this.searchForm.orgCode[this.searchForm.orgCode.length - 1]
        path: orgCode
      }
      */
      data.path = orgCode
      data.orgCode = orgCode
      this.$api.kefuExport(data).then((res) => {
        console.log(res, 'res')
        this.downloadlink(res.data)
        this.loadingStateTwo = false
      }).catch((err) => {
        console.log(err)
      })
    },
    // 订单导出
    onApplierExport () {
      let params = {
        pageNo: this.page.pageNo,
        pageSize: this.page.pageSize,
        status: this.currentTab
      }
      params = Object.assign(params, this.searchForm)
      params.status = this.currentTab == 8 ? '' : this.currentTab
      params.orgCode = params.orgCode[params.orgCode.length - 1]
      // if (this.currentTab === this.currentTabStatus.underReview) { params.approveStatus = 1 }
      // 去除字符串 前后 空格
      for (const item in params) {
        if (typeof params[item] === 'string') {
          params[item] = params[item].trim()
        }
      }
      if (params.orderTimeStart === '' || params.orderTimeEnd === '') {
        return this.$message.warning('请选择时间！')
      }
      if (this.searchForm.orgCode.length === 0) {
        console.log(this.searchForm.orgCode)
        return this.$message.warning('请选择公司部门！')
      }
      this.$api.applierExport(params).then((res) => {
        this.downloadlink(res.data)
      }).catch((err) => {
        console.log(err)
      })
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    }
  }
}
</script>

<style scoped lang="scss">

.page{
  text-align: center;
  margin: 10px auto;
}

/deep/ .hide-content {
  display: none !important;
}

/deep/ .show-content {
  display: inline-block;
}

/deep/ .el-link {
  margin: 0 5px;
}

.search-form .el-form-item {
  width: 100%;
  max-width: 295px;
  min-width: 250px;
  margin-right: 10px;
}

/deep/ .el-table th > .cell, /deep/ .el-table td {
  text-align: unset;
}

.tabclass {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.yellowBtn, .blueBtn, .serviceDerive, .promotionDerive {
  height: 36px;
  border-radius: 4px;
  margin-bottom: 10px;
}

.yellowBtn {
  //width: 160px;
  //height: 36px;
  background: #EDB840;
  //border-radius: 4px;
}

.blueBtn {
  //width: 120px;
  //height: 36px;
  background: #4168E7;
  //border-radius: 4px;
}

.serviceDerive {
  //width: 160px !important;
  background: #67c23a !important;
}

.promotionDerive {
  //width: 160px !important;
  background: #e6a23c !important
}

.serviceDeriveTwo {
  //width: 160px !important;
  background: #0f82c5 !important;
}

.promotionDeriveTwo {
  //width: 160px !important;
  background: #b705fd !important
}

.tabBtn {
  //width: 100px;
  height: 36px;
  padding: 0 12px;
  border-radius: 4px;
  margin-bottom: 10px;
}

/deep/ .el-tabs {
  margin-top: 20px;

  .el-tabs__header {
    .el-tabs__nav-wrap {
      .el-tabs__nav-scroll {
        padding: 0;

        .el-tabs__nav {
          .el-tabs__active-bar {
            display: none;
          }

          .el-tabs__item {
            margin-right: 20px;
            width: 120px;
            height: 36px;
            padding: 0;
            text-align: center;
            line-height: 36px;
            font-size: 16px;
            color: #999999;
            border-radius: 4px;
            background: #ececec;
          }

          .el-tabs__item.is-active {
            color: #333333;
            background: #e3edff;
          }
        }
      }
    }
  }

  .el-tabs__nav-wrap::after {
    display: none;
  }
}

.shopTitle {
  margin-bottom: 20px;
}

/deep/ .el-button {
  border: none;
}

.search-form {
  .el-form-item {
    max-width: 312px;
    /deep/ .el-form-item__label {
      width: 100px;
    }

    /deep/ .el-form-item__content {
      width: calc(100% - 100px);

      .el-date-editor {
        //width: calc(100% - 82px);
      }
    }

  }
}

.orderNotes {
  margin-top: 24px;
  padding-bottom: 25px;
  border-bottom: 1px solid #D9D9D9;

  .headerOrder {
    .orderRemak {
      margin-bottom: 12px;
      font-size: 18px;
    }
  }

}

/deep/ .el-textarea__inner {
  height: 132px;
}

.statistics {
  margin-top: 30px;
  display: flex;
  justify-content: right;
  align-items: center;

  .fourteen {
    font-size: 14px;
    padding-right: 20px;
  }

  .blue {
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: bold;
    line-height: 0px;
    color: #4168E7;
  }
}

.present {
  display: flex;
  justify-content: right;
  height: 36px;
  margin-top: 30px;
  padding-bottom: 28px;

}

.tabsBtn {
  display: flex;
}

.dialogBtnright {
  display: flex;
  justify-content: space-between;
}

.dialogBtnright_right {
  display: flex;
  justify-content: right !important;

}

.setPay_payment_btn_quxiao {
  width: 120px;
  height: 36px;
  border: 1px solid #D9D9D9;
  background-color: #ffffff;
  color: rgba(153, 153, 153, 1);
  border-radius: 4px;
  line-height: 0;
}

.setPay_payment_btn_queren {
  width: 120px;
  height: 36px;
  background: #4168E7;
  opacity: 1;
  border-radius: 4px;
  line-height: 0;
  border: 0;
}

.setPay_payment {
  display: block;
  margin-bottom: 15px;
}

.dialog-btn {
  text-align: right;
}

/deep/ .el-table__row td .cell p {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1; /* 可以显示的行数，超出部分用...表示*/
  -webkit-box-orient: vertical;
}

/*
/deep/.el-table__row td .cell span, /deep/.el-table__row td .cell div p{
  display: block;
  overflow : hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
*/
/deep/ .el-scrollbar {
  height: 10px;
}

/deep/ .el-scrollbar__bar.is-horizontal {
  height: 9px;

}
::v-deep .el-form-item__label{
  padding:0px 10px 0 0
}
</style>
